# 用于画图，输出例图见“例图1”

import matplotlib.pyplot as plt
import numpy as np

config = {
    "font.family": 'serif',
    "font.size": 12,
    "mathtext.fontset": 'stix',
    # "font.serif": ['SimSun'],
    "font.serif": ['Times New Roman'],
    'axes.unicode_minus':False,
    'xtick.direction':'in',
    'ytick.direction':"in"
}
plt.rcParams.update(config)

# 画出图片
def show(save_path=None):
    '''
    # 输入参数
    save_path:为None时，将图片展示在屏幕上，否则将图片保存在路径"save_path"下
    '''
    # plt.legend()   # 图例
    plt.grid()
    # plt.xlim([0, 100])
    plt.xlabel('相位$\mathrm{Phase}$', fontsize=14,fontdict={"family":"SimSun"})
    plt.ylabel('归一化位移', fontsize=14,fontdict={"family":"SimSun"})
    plt.tick_params(labelsize=14)
    plt.xticks([0,0.25,0.5,0.75,1],(0,"$\\mathrm{π/2}$","$\\mathrm{π}$","$\\mathrm{3π/2}$","$\\mathrm{2π}$"),fontproperties='Times New Roman')
    plt.yticks(fontproperties='Times New Roman')
    plt.legend(prop={'family' : 'SimSun'})
    plt.tight_layout()
    if save_path is None:
        plt.show()
    else:
        plt.savefig(save_path)


if __name__=="__main__":
    x=np.linspace(0,1,100)
    y=np.sin(x*2*np.pi)

    plt.figure(figsize=(4,3),dpi=600)
    plt.plot(x,y,label="正弦")
    show("例图1")
    pass